import java.util.ArrayList;
import java.util.Scanner;

/**
 * 考生需要模拟实现一个简单的自动售货系统，实现投币、购买商品、退币、查询库存商品及存钱盒信息的功能。
 */
public class SaleGoods {
    static int goodTotal;
    static int moneyTotal;
    static ArrayList<Goods> goods = new ArrayList<>();
    static ArrayList<Money> monies = new ArrayList<>();


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String str = scanner.nextLine();
            String[] commandList = str.split(";");
            for (int i = 0; i < commandList.length; i++) {
                if(commandList[i].contains("r")){
                    rFunc(commandList[i]);
                }else if(commandList[i].contains("p")){
                    pFunc(commandList[i]);
                }else if(commandList[i].contains("b")){
                    bFunc(commandList[i]);
                }else if(commandList[i].contains("c")){
                    cFunc(commandList[i]);
                }else if(commandList[i].contains("q")){
                    qFunc(commandList[i]);
                }
            }
        }
    }

    private static void qFunc(String s) {
        if(!s.contains(" ")){
            System.out.println("E010:Parameter error");
            return;
        }

        String[] strings = s.split(" ");
        int num = Integer.parseInt(strings[1]);
        if(num<0 || num>1){
            System.out.println("E010:Parameter error");
            return;
        }

        if(num == 0){
            Goods good = null;
            for (int i = 0; i < goods.size(); i++) {
                good = goods.get(i);
                System.out.println(good.name+" "+good.price+" "+good.count);
            }
        }else {
            Money money = null;
            for (int i = 0; i < monies.size(); i++) {
                money = monies.get(i);
                System.out.println(money.num + " yuan coin number=" + money.count);
            }
        }

    }

    private static void cFunc(String s) {
        if(moneyTotal == 0){
            System.out.println("E009:Work failure");
            return;
        }

        int tenCount = 0;
        int fiveCount = 0;
        int twoCount = 0;
        int oneCount = 0;

        while (moneyTotal >= 10 && monies.get(3).count > 0){
            moneyTotal -= 10;
            monies.get(3).count -= 1;
            tenCount++;
        }
        while (moneyTotal >= 5 && monies.get(2).count > 0){
            moneyTotal -= 5;
            monies.get(2).count -= 1;
            fiveCount++;
        }
        while (moneyTotal >= 2 && monies.get(1).count > 0){
            moneyTotal -= 2;
            monies.get(2).count -= 1;
            twoCount++;
        }
        while (moneyTotal >= 1 && monies.get(0).count > 0){
            moneyTotal -= 1;
            monies.get(0).count -= 1;
            oneCount++;
        }

        moneyTotal = 0;
        System.out.println("1 yuan coin number=" + oneCount);
        System.out.println("2 yuan coin number=" + twoCount);
        System.out.println("5 yuan coin number=" + fiveCount);
        System.out.println("10 yuan coin number=" + tenCount);

    }

    private static void bFunc(String s) {
        String[] strings = s.split(" ");
        String num = strings[1];
        boolean flag = false;
        Goods good = null;
        for (int i = 0; i < goods.size(); i++) {
            if(goods.get(i).name.equals(num)){
                flag = true;
                good = goods.get(i);
                break;
            }
        }

        if(!flag){
            System.out.println("E006:Goods does not exist");
            return;
        }

        if(goodTotal == 0){
            System.out.println("E007:The goods sold out");
            return;
        }

        if(moneyTotal < good.price){
            System.out.println("E008:Lack of balance");
            return;
        }

        moneyTotal -= good.price;

        System.out.println("S003:Buy success,balance=" + moneyTotal);


    }

    private static void pFunc(String s) {
        String[] strings = s.split(" ");
        int num = Integer.parseInt(strings[1]);
        if(num != 1 && num != 2 && num != 5 && num != 10){
            System.out.println("E002:Denomination error");
            return;
        }
        if(num > 2 && monies.get(0).count + monies.get(1).count * 2 < num){
            System.out.println("E003:Change is not enough, pay fail");
            return;
        }

        if(goodTotal == 0){
            System.out.println("E005:All the goods sold out");
            return;
        }

        moneyTotal+=num;

        if(num == 1){
            monies.get(0).count+=1;
        }else if(num == 2){
            monies.get(1).count+=1;
        }else if(num == 5){
            monies.get(2).count+=1;
        }else {
            monies.get(3).count+=1;
        }
        System.out.println("S002:Pay success,balance="+moneyTotal);
    }

    private static void rFunc(String s) {
        String[] strings = s.split(" ");
        String[] goodList = strings[1].split("_");
        for (int i = 0; i < goodList.length; i++) {
            int count = Integer.parseInt(goodList[i]);
            goodTotal+=count;
            goods.get(i).count = count;
        }
        String[] moneyList = strings[2].split("_");
        for (int i = 0; i < moneyList.length; i++) {
            monies.get(i).count = Integer.parseInt(moneyList[i]);
        }
        moneyTotal = 0;
        System.out.println("S001:Initialization is successful");
    }
}
class Goods{
    String name;
    int price;
    int count;

    public Goods(String name, int price) {
        this.name = name;
        this.price = price;
    }
}

class Money{
    int num;
    int count;

    public Money(int num) {
        this.num = num;
    }
}
